package com.king.juc.threads;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.LockSupport;

/**
 * @author king
 * @date 2020/9/27 13:39
 */
@Slf4j(topic = "c.LockSupportDemo")
public class LockSupportDemo {
    public static void main(String[] args) throws InterruptedException {
        park();
    }

    private static void park() throws InterruptedException {
        Thread t1 = new Thread(() -> {
            log.debug("park...");
            // 禁用当前线程
            LockSupport.park();
            log.debug("unpark...");
//            log.debug("打断状态: {}", Thread.currentThread().isInterrupted());
            // 将打断标记设置为 false, 这样就可以使 park重新生效
            log.debug("打断状态: {}", Thread.interrupted());

            LockSupport.park();
            log.debug("unpark...");
        }, "t1");
        t1.start();

        Thread.sleep(1000);
        t1.interrupt();
    }
}
